// pages/user/user.js
const $ = require("../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: "",
    orderIconList: [{
        icon: "/image/user/order-icon-daifukuan.png",
        text: "待付款",
        typeId: 1,
        num: '' //当有值时显示红色角标
      },
      {
        icon: "/image/user/order-icon-daifahuo.png",
        text: "待发货",
        typeId: 2,
        num: ''
      },
      {
        icon: "/image/user/order-icon-daishouhuo.png",
        text: "待收货",
        typeId: 3,
        num: ''
      },
      {
        icon: "/image/user/order-icon-yiwancheng.png",
        text: "已完成",
        typeId: 4,
        num: ''
      },
    ],
    orderIconList2: [{
        icon: "/image/user/youhui-icon-1.png",
        text: "待使用",
        typeId: 0
      },
      {
        icon: "/image/user/youhui-icon-2.png",
        text: "已使用",
        typeId: 1
      },
      {
        icon: "/image/user/youhui-icon-3.png",
        text: "过期关闭",
        typeId: 2
      }
    ],
  },
  godingdan(e) {
    let typeId = e.currentTarget.dataset.typeid
    console.log(typeId);
    wx.navigateTo({
      url: '/pages/dingdan/dingdan?typeId=' + typeId,
    })
  },
  goyouhui(e) {
    let id = e.currentTarget.dataset.typeid
    wx.navigateTo({
      url: '/pages/youhuiquan/youhuiquan?typeId=' + id,
    })

  },
  getlist() {
    $.axios({
      url: "user/index",
      method: "GET",
      data: {
        showType: 0,
        page: 1,
        limit: 8
      },
      header: {
        "X-Byesame-Token": wx.getStorageSync('token')
      }
    }).then(res => {
      this.setData({
        orderIconList: [{
            icon: "/image/user/order-icon-daifukuan.png",
            text: "待付款",
            typeId: 1,
            num: res.data.data.order.unpaid //当有值时显示红色角标
          },
          {
            icon: "/image/user/order-icon-daifahuo.png",
            text: "待发货",
            typeId: 2,
            num: res.data.data.order.unship
          },
          {
            icon: "/image/user/order-icon-daishouhuo.png",
            text: "待收货",
            typeId: 3,
            num: res.data.data.order.unrecv
          },
          {
            icon: "/image/user/order-icon-yiwancheng.png",
            text: "已完成",
            typeId: 4,
            num: res.data.data.order.uncomment
          },
        ],
      })


    })

  },
  goMore(e) {
    let type = e.currentTarget.dataset.type
    wx.navigateTo({
      url: '/pages/usermore/usermore?type=' + type,
    })
  },

  // 转跳设置
  touserInformation(){
    wx.navigateTo({
      url:"/pages/userInformation/userInformation"
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // if (!wx.getStorageSync('token')) {
    //   wx.redirectTo({
    //     url: "/pages/login/login"
    //   })
    // } else {
      this.setData({
        username: wx.getStorageSync('name')
      })
    // }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
		this.getlist()
		$.getitime()
		$.getendtime()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})